<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')"/>
    <style>
        /* 收货确认弹窗样式 */
        .confirm-receive-modal .modal-body h4 {
            font-weight: bold;
            margin-bottom: 15px;
        }
        .confirm-receive-modal .modal-body .text-muted {
            font-size: 13px;
            color: #666;
        }
        .receive-warning-icon {
            color: #5cb85c;
            font-size: 24px;
            margin-right: 10px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <!-- 新增收货确认模态框 -->
    <div class="modal fade confirm-receive-modal" id="confirmReceiveModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title"><i class="fa fa-check-circle receive-warning-icon"></i>确认收货</h4>
                </div>
                <div class="modal-body">
                    <h4>请确认您是否已收到物品？</h4>
                    <p class="text-muted">确认收货后订单完结，无法撤销操作</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="confirmReceiveBtn">确认收货</button>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('system:orders:remove')}]];
    var prefix = ctx + "system/user/orders";

    $(function () {
        var options = {
            url: prefix + "/myList",
            createUrl: prefix + "/add",
            readUrl: prefix + "/read/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "",
            columns: [{
                checkbox: true
            },
                {
                    field: 'index',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    field: 'orderAmount',
                    title: '订单金额'
                },
                {
                    field: 'orderCustomer',
                    title: '买单客户'
                },
                {
                    field: 'address',
                    title: '地址'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.read(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');

                        // 新增确认收货按钮
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="showReceiveConfirm(\'' + row.id + '\')"><i class="fa fa-check"></i>确认收货</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 显示收货确认弹窗
    var currentReceiveOrderId = null;
    function showReceiveConfirm(orderId) {
        currentReceiveOrderId = orderId;
        $('#confirmReceiveModal').modal('show');
    }

    // 确认收货操作
    $('#confirmReceiveBtn').click(function () {
        if (!currentReceiveOrderId) return;

        $.ajax({
            url: prefix + "/confirmReceipt/" + currentReceiveOrderId,
            type: 'POST',
            success: function (response) {
                if (response.code === 0) {
                    $.modal.msgSuccess("收货成功");
                    $('#confirmReceiveModal').modal('hide');
                    $.table.refresh(); // 刷新表格
                } else {
                    $.modal.alertError(response.msg || "操作失败");
                }
            },
            error: function () {
                $.modal.alertError("请求失败，请稍后再试");
            }
        });
    });
</script>
</body>
</html>